package com.wzapp.sitposture.setup.repository;

import com.wzapp.sitposture.setup.entity.Setup;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.rest.core.annotation.RepositoryRestResource;

import java.util.List;

/**
 * Created by qianglong on 2018/1/15.
 */
@RepositoryRestResource(path="setups", exported = false)
public interface SetupRepository extends JpaRepository<Setup,String>{

    /**
     * 功能: 根据分组类型，状态查询配置列表<br/>
     *
     * @author ql
     * @create 2018-05-08 20:19
     * @param groupType
     * @param status
     * @return java.util.List<Setup>
     **/
    @Query(value = "select * from config_setup where group_type =?1 and version <= ?2 and status=?3 order by sort_num",nativeQuery = true)
    List<Setup> findByGroupTypeAndVersionAndStatusOrderBySortNum(String groupType, String version, String status);

    /**
     *  获取一个配置
     * @param groupType
     * @return
     */
    Setup findTop1ByGroupType(String groupType);
}
